/**
 * Created with IntelliJ IDEA.
 * Description:字符串变形
 * User: wangxin
 * Date: 2025-02-25
 * Time: 22:22
 */
public class Test {
    public String trans (String s, int n) {
        // write code here
        if(n == 0){
            return s;
        }
        StringBuffer res = new StringBuffer();
        for(int i = 0;i < n;i++){
            if(s.charAt(i) >= 'a'&&s.charAt(i)<='z'){
                res.append((char)(s.charAt(i)-'a'+'A'));
            }else if(s.charAt(i) >= 'A'&&s.charAt(i)<='Z'){
                res.append((char)(s.charAt(i)-'A'+'a'));
            }else{
                res.append(s.charAt(i));
            }
        }
        res = res.reverse();
        for(int i = 0;i < n;i++){
            int j = i;
            while(j < n&&res.charAt(j)!=' ')
                j++;
            String temp = res.substring(i,j);
            StringBuffer sb = new StringBuffer(temp);
            temp = sb.reverse().toString();
            res.replace(i,j,temp);
            i=j;
        }
        return res.toString();
    }
}
